package com.itheima.reggie.common;

import com.itheima.reggie.exception.CategoryBusinessException;
import com.itheima.reggie.exception.CustomException;
import com.itheima.reggie.exception.DishBusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Lff
 * @date 2022/2/25
 */
//@RestControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public R<String> exception(Exception ex) {
        log.error("错误：{}", ex.getMessage());
        return R.error("未知异常");
    }

    @ExceptionHandler(CategoryBusinessException.class)
    public R<String> categoryBusinessException(CategoryBusinessException ex) {
        String message = ex.getMessage();
        return R.error(message);
    }


    @ExceptionHandler(DishBusinessException.class)
    public R<String> dishBusinessException(DishBusinessException ex) {
        String message = ex.getMessage();
        return R.error(message);
    }
    @ExceptionHandler(CustomException.class)
    public R<String> customException(CustomException ex) {
        String message = ex.getMessage();
        return R.error(message);
    }
}
